package com.coolbi.onsupai.core.dao.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;

import com.coolbi.onsupai.core.dao.SmsDao;
import com.coolbi.onsupai.core.entity.Sms;
import com.coolbi.onsupai.core.mapper.SmsMapper;

public class SmsDaoImpl implements SmsDao {

	@Autowired
	private SmsMapper smsMapper;
	
	@Override
	public Sms save(Sms obj) {
		smsMapper.save(obj);
		return obj;
	}

	@Override
	public int delete(long id) {
		return smsMapper.delete(id);
	}

	@Override
	public int update(Sms obj) {
		return smsMapper.update(obj);
	}

	@Override
	public Sms get(long id) {
		return smsMapper.get(id);
	}

	@Override
	public List<Sms> list() {
		return smsMapper.list();
	}

	@Override
	public List<Sms> listByPage(int offset, int limit) {
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("offset", offset);
		parameter.put("limit", limit);
		return smsMapper.listByPage(parameter);
	}

	@Override
	public List<Sms> find(Map<String, Object> parameter) {
		return smsMapper.listByParameter(parameter);
	}

	@Override
	public List<Sms> findByPage(Map<String, Object> parameter, int offset,
			int limit) {
		parameter.put("offset", offset);
		parameter.put("limit", limit);
		return smsMapper.listByParameterPage(parameter);
	}

	@Override
	public List<Sms> search(Map<String, Object> parameter, int offset, int limit) {
		parameter.put("offset", offset);
		parameter.put("limit", limit);
		return smsMapper.search(parameter);
	}

	@Override
	public int count() {
		return smsMapper.count();
	}

	@Override
	public int countByKeyWord(Map<String, Object> parameter) {
		return smsMapper.countByKeyWord(parameter);
	}

	@Override
	public int count(Map<String, Object> parameter) {
		return smsMapper.countByParameter(parameter);
	}

	public void setSmsMapper(SmsMapper smsMapper) {
		this.smsMapper = smsMapper;
	}

	@Override
	public List<Sms> findByPage(Long id, Boolean isReaded, Integer smsType,
			int offset, int limit) {
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("addresserId", id);
		parameter.put("isReaded", isReaded);
		parameter.put("smsType", smsType);
		parameter.put("offset", offset);
		parameter.put("limit", limit);
		return smsMapper.listSms(parameter);
	}

	@Override
	public int count(Long id, Boolean isReaded, Integer smsType) {
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("addresserId", id);
		parameter.put("isReaded", isReaded);
		parameter.put("smsType", smsType);
		return smsMapper.countSms(parameter);
	}

	@Override
	public List<Sms> findByPage(Long id, int offset, int limit) {
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("addresserId", id);
		parameter.put("offset", offset);
		parameter.put("limit", limit);
		return smsMapper.listByUserId(parameter);
	}

	@Override
	public int count(Long id) {
		return smsMapper.countByUserId(id);
	}

	@Override
	public int updateReadStatus(Long id, Boolean isReaded) {
		Map<String, Object> parameter = new HashMap<String, Object>();
		parameter.put("id", id);
		parameter.put("isReaded", isReaded);
		return smsMapper.updateReadStatus(parameter);
	}

}
